#!/bin/bash

echo -e "\033[32m>>>>>>>>更新系统内核，请耐心等待！\033[0m"
# 安装依赖软件
dnf -y install kernel-devel gcc make dkms gcc-c++ git vim fish pciutils docker-ce chrony openblas-devel openeuler-lsb

# 设置中国时区
rm -rf /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

timedatectl set-timezone Asia/Shanghai
localectl set-locale LANG=zh_CN.UTF-8
source /etc/locale.conf
timedatectl set-ntp yes

# 设置ntp服务器 重启
echo 'server ntp2.aliyun.com iburst' >>/etc/chrony.conf

# 配置docker加速
touch /etc/docker/daemon.json
echo '{
    "registry-mirrors": [
        "https://docker.linkos.org",
        "https://docker.linkos.org",
        "https://dockerproxy.com",
        "https://mirror.baidubce.com",
        "https://docker.nju.edu.cn",
        "https://docker.mirrors.sjtug.sjtu.edu.cn/",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.m.daocloud.io",
        "https://reg-mirror.qiniu.com"
    ],
    "features": {
        "containerd-snapshotter": true"
    }
}' | sudo tee -a /etc/docker/daemon.json

systemctl enable --now ntpd
systemctl enable docker
systemctl restart docke

# python3-pipx
dnf install -y python3-pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

# 屏蔽系统自带驱动 /usr/lib/modprobe.d/nvidia-utils.conf
cat <<EOF >>/usr/lib/modprobe.d/dist-blacklist.conf
blacklist nouveau
options nouveau modeset=0
EOF
# 重建内核
rm -rf /boot/initramfs-$(uname -r).img
dracut /boot/initramfs-$(uname -r).img $(uname -r)

echo -e "\033[32m>>>>>>>>系统即将重启！\033[0m"

reboot

# 显卡驱动（CUDA驱动）：向下兼容的，可以一直保持最新。
# wget https://developer.download.nvidia.com/compute/cuda/12.3.1/local_installers/cuda_12.3.1_545.23.08_linux.run
# /etc/profile文件
# echo export PATH=${PATH}:/usr/local/cuda-12.3/bin >> /etc/profile
# echo export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda-12.3/lib64 >> /etc/profile

# lspci | grep nouveau
# lspci | grep -i nvidia
